package org.bean;

import org.example.bean.Production;

import java.util.List;

public class SLRProduction extends Production {
    public List<String> slrRight;

    public SLRProduction(String left ,List<String> slrRight){
        this.left = left;
        this.slrRight=slrRight;
    }



    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(left).append("->");
        for (String s : slrRight) {
            stringBuilder.append(s);
        };
        return stringBuilder.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        SLRProduction other = (SLRProduction) obj;
        if(!left.equals(other.left))return false;
        if(slrRight.size()!=other.slrRight.size())return false;
        int len=slrRight.size();
        for(int i=0;i<len;i++){
            if(!slrRight.get(i).equals(other.slrRight.get(i)))
                return false;
        }
//        for (String s : slrRight) {
//            boolean isIn=false;
//            for (String string : other.slrRight) {
//                if(s.equals(string)){
//                    isIn=true;
//                    break;
//                }
//            };
//            if(isIn)continue;
//            else return false;
//        }
        return true;
    }
//
////    @Override
//    public boolean equals(Object obj) {
//        if (this == obj) {
//            return true;
//        }
//        if (obj == null || getClass() != obj.getClass()) {
//            return false;
//        }
//        SLRProduction other = (SLRProduction) obj;
//        return Objects.equals(left, other.left) && Objects.equals(slrRight, other.slrRight);
//    }

//    @Override
//    public int hashCode() {
//        return Objects.hash(left, slrRight);
//    }

    public String toStringRemoveDot(){
        //好像与toString重复了，先保留
        StringBuilder str = new StringBuilder();
        str.append(left);
        str.append("->");
        for (String s : slrRight) {
            if(s.equals("·"))continue;
            str.append(s);
        };
        return str.toString();
    }
}
